package cn.kgc.tangcco.io.inputstreamandoutputstram;

import org.junit.Test;

import java.io.*;

/**
 * @author 李昊哲
 * @Description
 * @create 2020/9/9 下午2:03
 */
public class InputStreamAndOutPutstreamTest02 {
    @Test
    public void test01() {
        try {
            // 目标文件
            OutputStream outputStream = new FileOutputStream("src/main/resources/a.txt");
            // 准备写入的字符串
            String content = "http://www.ekgc.cn";
            byte[] bytes = content.getBytes();
            outputStream.write(bytes);
            System.out.println("写入完成");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    @Test
    public void test02() {
        try {
            // 目标文件
            OutputStream outputStream = new FileOutputStream("src/main/resources/a.txt", true);
            // 准备写入的字符串
            String content = "\ngood good study day day up";
            byte[] bytes = content.getBytes();
            outputStream.write(bytes);
            outputStream.flush();
            System.out.println("写入完成");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    @Test
    public void test03() {
        try {
            // 目标文件
            OutputStream outputStream = new FileOutputStream("src/main/resources/a.txt", true);
            // 准备写入的字符串
            String content = "\n刘晓兰";
            byte[] bytes = content.getBytes();
            outputStream.write(bytes);
            outputStream.flush();
            System.out.println("写入完成");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
